const port = process.env.port || process.env.npm_config_port || 9527 // dev port
module.exports = {
    lintOnSave: false,
    chainWebpack: config => {
        // 发布模式
        config.when(process.env.NODE_ENV === 'production', config => {
                config
                    .entry('app')
                    .clear()
                    .add('./src/main-prod.js')

                config.set('externals', {
                    vue: 'Vue',
                    'vue-router': 'VueRouter',
                    axios: 'axios',
                    lodash: '_',
                    echarts: 'echarts',
                    nprogress: 'NProgress',
                    'vue-quill-editor': 'VueQuillEditor'
                })

                config.plugin('html').tap(args => {
                    args[0].isProd = true
                    return args
                })
            }),

            // 开发模式
            config.when(process.env.NODE_ENV === 'development', config => {
                config
                    .entry('app')
                    .clear()
                    .add('./src/main-dev.js'),

                    config.plugin('html').tap(args => {
                        args[0].isProd = false
                        return args
                    })
            })
    },
    devServer: {
        port: port,
        open: true,
        overlay: {
            warnings: false,
            errors: true
        },
        // after: require('./mock/mock-server.js'),
        proxy: {
            '/dev-api/api/': {
                // target: `http://218.11.10.94:11300/api/`,
                // target: `https://test.shike.cn/SK3000WebCore/api/`,
                // target: `http://121.41.87.203:11300/`,
                // target: `http://192.168.2.26:12307/`,
                // target: `http://121.26.195.174:11300/`,
                // target: `http://localhost:11300/`,
                // target: `http://221.238.102.211:11300/`,
                // target: `http://192.168.18.95:11300/`,
                // target: `http://192.168.2.19:11300/`,
                target: `http://59.57.4.66:11300/`,
                // target: `http://124.232.146.55:11300/`,
                // target: `http://59.57.4.66:11300/`,
                logLevel: 'debug',
                pathRewrite: {
                    '^/dev-api/api': 'api'
                }
            },
            '/userid-api/': {
                target: `http://121.41.87.203:11300/`,
                // target: `http://192.168.2.26:12307/`,
                logLevel: 'debug',
                pathRewrite: {
                    '^/userid-api': ''
                }
            },
            '/AuthorizeClientHub': {
                target: `ws://192.168.2.18:11300/`,
                logLevel: 'debug',
                pathRewrite: {
                    '^/AuthorizeClientHub': 'AuthorizeClientHub'
                },
                ws: true
            }
        }
    },
}